package com.ruoyi.voucher.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.voucher.mapper.SummaryMapper;
import com.ruoyi.voucher.domain.Summary;
import com.ruoyi.voucher.service.ISummaryService;

/**
 * 常用摘要Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-25
 */
@Service
public class SummaryServiceImpl implements ISummaryService 
{
    @Autowired
    private SummaryMapper summaryMapper;

    /**
     * 查询常用摘要
     * 
     * @param summaryId 常用摘要主键
     * @return 常用摘要
     */
    @Override
    public Summary selectSummaryBySummaryId(Long summaryId)
    {
        return summaryMapper.selectSummaryBySummaryId(summaryId);
    }

    /**
     * 查询常用摘要列表
     * 
     * @param summary 常用摘要
     * @return 常用摘要
     */
    @Override
    public List<Summary> selectSummaryList(Summary summary)
    {
        return summaryMapper.selectSummaryList(summary);
    }

    /**
     * 新增常用摘要
     * 
     * @param summary 常用摘要
     * @return 结果
     */
    @Override
    public int insertSummary(Summary summary)
    {
        List<Summary> summaries = summaryMapper.selectSummaryList(summary);
        if (summaries.size() > 0) {
            return 0;
        }
        return summaryMapper.insert(summary);
    }

    /**
     * 修改常用摘要
     * 
     * @param summary 常用摘要
     * @return 结果
     */
    @Override
    public int updateSummary(Summary summary)
    {
        List<Summary> summaries = summaryMapper.selectSummaryList(summary);
        if (summaries.size() > 0) {
            return 0;
        }
        return summaryMapper.updateById(summary);
    }

    /**
     * 批量删除常用摘要
     * 
     * @param summaryIds 需要删除的常用摘要主键
     * @return 结果
     */
    @Override
    public int deleteSummaryBySummaryIds(Long[] summaryIds)
    {
        int a = 0;
        for (Long summaryId : summaryIds) {
            summaryMapper.updateById(Summary.builder().isDeleted(0).summaryId(summaryId).build());
            a++;
        }
        return a;
    }

    /**
     * 删除常用摘要信息
     * 
     * @param summaryId 常用摘要主键
     * @return 结果
     */
    @Override
    public int deleteSummaryBySummaryId(Long summaryId)
    {
        return summaryMapper.updateById(Summary.builder().isDeleted(0).summaryId(summaryId).build());
    }
}
